/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年5月28日
 */
package com.massyframework.beanskin.runtime.modular.assembly;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import com.massyframework.beanskin.assembly.AssemblyConfig;
import com.massyframework.beanskin.assembly.ServletModel;
import com.massyframework.beanskin.runtime.modular.DefaultInitParamsConfig;
import com.massyframework.beanskin.service.DependencyServiceDescriptor;
import com.massyframework.beanskin.service.ExportServiceDescriptor;
import com.massyframework.beanskin.util.version.VersionRange;

/**
 * 装配件配置项
 * @author huangkh
 *
 */
final class DefaultAssemblyConfig extends DefaultInitParamsConfig
	implements AssemblyConfig{

	private String[] configLocations;
	private Class<?>[] configTypes;
	private List<DependencyServiceDescriptor<?>> dependencies;
	private List<ExportServiceDescriptor> exports;
	
	private ServletModel servletModel = ServletModel.NONE;
	
	private String beanContextName;
	private VersionRange versionRange;
	
	/**
	 * 构造方法
	 * @param builder
	 */
	public DefaultAssemblyConfig(DefaultAssemblyBuilder builder) {
		super(builder);
		this.beanContextName = Objects.requireNonNull(builder.beanContextName, "\"beanContextName\" cannot be null.");
		this.versionRange = Objects.requireNonNull(builder.versionRange, "\"versionRange\" cannot be null.");
		this.configLocations = builder.configLocations == null ?
				new String[0] :
					builder.configLocations.toArray(new String[builder.configLocations.size()]);
		this.configTypes = builder.configTypes == null ?
			new Class<?>[0] :
				builder.configTypes.toArray(new Class<?>[builder.configTypes.size()]);
		this.dependencies = builder.dependencies == null ?
				Collections.emptyList() :
					Collections.unmodifiableList(builder.dependencies);
		this.exports = builder.exports == null ?
				Collections.emptyList() :
					Collections.unmodifiableList(builder.exports);
		this.servletModel = builder.servletModel;
	}
	
	

	@Override
	public String getBeanContextName() {
		return this.beanContextName;
	}

	@Override
	public String[] getConfigLocations() {
		return this.configLocations;
	}

	@Override
	public Class<?>[] getConfigTypes() {
		return this.configTypes;
	}

	@Override
	public List<DependencyServiceDescriptor<?>> getDependencyServiceDescriptors() {
		return this.dependencies;
	}

	@Override
	public List<ExportServiceDescriptor> getExportServiceDescriptors() {
		return this.exports;
	}

	@Override
	public ServletModel getServletModel() {
		return this.servletModel;
	}

	@Override
	public VersionRange getVersionRangeWithBeanContext() {
		return this.versionRange;
	}
	
}
